[worker] Resolve runtime cache settings from job env and fallback on npm cache failures#3855
[worker] Resolve runtime cache settings from job env and fallback on npm cache failures#3855AbbanMustafa wants to merge 10 commits into
Conversation
…npm cache failures
|
Subscribed to pull request
Generated by CodeMention |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3855 +/- ##
==========================================
+ Coverage 58.42% 58.48% +0.07%
==========================================
Files 917 919 +2
Lines 39994 40129 +135
Branches 8418 8445 +27
==========================================
+ Hits 23363 23467 +104
- Misses 16536 16566 +30
- Partials 95 96 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…npm cache failures
| useFrozenLockfile: boolean; | ||
| }): Promise<void> { | ||
| const npmCacheUrl = env.NPM_CONFIG_REGISTRY; | ||
| const npmCacheErrorTracker = createNpmCacheRegistryErrorTracker({ env, npmCacheUrl }); |
There was a problem hiding this comment.
this captures cache failures that npm only prints to stdout/stderr, like audit endpoint ENOTFOUND, so we still log them to Sentry when npm exits 0 and skips the catch/fallback path
| const cocoapodsCacheUrl = RuntimeSettings.getCocoapodsCacheUrl(); | ||
|
|
||
| setEnv(env, 'NPM_CACHE_URL', npmCacheUrl); | ||
| setEnv(env, 'NPM_CONFIG_REGISTRY', npmCacheUrl); |
There was a problem hiding this comment.
gosh it took me so long to find docs proving this should work lol
does this replace npm config set registry?
There was a problem hiding this comment.
Yes! they mention it here https://docs.npmjs.com/cli/v11/using-npm/config#environment-variables
Any environment variables that start with npm_config_ will be interpreted as a configuration parameter. For example, putting npm_config_foo=bar in your environment will set the foo configuration parameter to bar.
example
> echo "registry=https://from-npmrc.example" > /tmp/.npmrc
> npm config get registry --userconfig=/tmp/.npmrc
https://from-npmrc.example
> export NPM_CONFIG_REGISTRY=https://from-env.example
> npm config get registry --userconfig=/tmp/.npmrc
https://from-env.example
There was a problem hiding this comment.
should we remove call to npm config set registry then?
There was a problem hiding this comment.
I think we should! posted validation below
| const childLogger = buildLogger.child({ buildId }); | ||
| await RuntimeSettings.loadAsync({ | ||
| environment: config.env, | ||
| logger: childLogger, |
There was a problem hiding this comment.
so actually about this logger -- i don't think we should use the build-facing logger. i don't think we need users to see "Failed to fetch worker runtime settings, using defaults", especially if it's in an "(unnamed build phase)"
i kept this logger from the start so "if we ever were to inspect logs of the service" we would have a record of this failure. maybe it was a bad idea and we should just rely only on sentry and env vars printing as distinction?
| const cocoapodsCacheUrl = RuntimeSettings.getCocoapodsCacheUrl(); | ||
|
|
||
| setEnv(env, 'NPM_CACHE_URL', npmCacheUrl); | ||
| setEnv(env, 'NPM_CONFIG_REGISTRY', npmCacheUrl); |
There was a problem hiding this comment.
should we remove call to npm config set registry then?
| const enabled = | ||
| envOverride === '1' || | ||
| (envOverride !== '0' && runtimeSettings.caches?.[process.platform]?.npm); |
There was a problem hiding this comment.
i think if runtime settings is false we should NOT enable a given cache. runtime settings being false is for cache maintenance when we know it's going to not be available so even if a user has EAS_USE_NPM_CACHE we should not enable the cache for them
There was a problem hiding this comment.
thank you yes, adding back to allow for killswitch
|
⏩ The changelog entry check has been skipped since the "no changelog" label is present. |


Why
We want to enable npm cache proxy usage per build job, but the worker was loading runtime settings before the job environment was available. That meant job-scoped environment variables like
EAS_USE_NPM_CACHE=1https://github.com/expo/universe/pull/27727 could not control cache URL resolution.We also need cache proxy rollout to be safe: if the proxy is unavailable or misconfigured, builds should fall back to the normal npm registry behavior instead of failing during the post-prebuild install.
How
createBuildContext, where the job env is available.NPM_CONFIG_REGISTRYonly when the job has enabled npm cache usage.EAS_USE_NPM_CACHE=1NPM_CONFIG_REGISTRY, so npm falls back to project/user/default registry settings0.Test Plan
0EAS_USE_NPM_CACHEis not enabledEAS_USE_NPM_CACHE=1from www. Cache private network could not resolve/connect to the internal cache host, which reproduced the proxy failure path and confirmed the build retried through the normal npm registry behavior, and logged to sentryhttps://expoio.sentry.io/issues/7511993527/?environment=development&project=1837720&query=is%3Aunresolved&referrer=issue-stream&statsPeriod=14d
NOOP when env var is not set